﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace JAAF.Builders
{
    /// <summary>
    /// An exception thrown by a builder when an instance is requested
    /// for an abstaction that has not been registered with an implementation.
    /// </summary>
    [Serializable]
    public class MissingRegistrationException: Exception, ISerializable
    {
        /// <summary>
        /// The abstraction that has been requested but not registered.
        /// </summary>
        public readonly string Abstraction;

        /// <summary>
        /// Creates a new intance of the <see cref="MissingRegistrationException"/> type.
        /// </summary>
        /// <param name="_sAbstraction"></param>
        public MissingRegistrationException(string _sAbstraction)
            :base(string.Format(Properties.Resources.ERR_MISSING_REGISTRATION, _sAbstraction))
        {
        }


        #region Serialization

        protected MissingRegistrationException(SerializationInfo _oInfo, StreamingContext _oCtx)
            : base(_oInfo, _oCtx)
        {
            this.Abstraction = (string)_oInfo.GetValue("Abstraction", typeof(string));
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            info.AddValue("Abstraction", this.Abstraction, typeof(string));
        }

        #endregion
    }
}
